﻿--|--------------------------------------------------------------------------------
--| [InsertGPSPoint] - Insert Procedure Script for GPSPoint
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[InsertGPSPoint]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[InsertGPSPoint]
GO

CREATE PROCEDURE [dbo].[InsertGPSPoint]
(
	@EntityID int,
	@GameID int,
	@UserID int,
	@Latitude float,
	@Longitude float,
	@Speed float,
	@Altitude float
)
AS
	SET NOCOUNT ON
	
	DECLARE  @EntityName nvarchar(50),
			 @GameName nvarchar(50),
			 @Login nvarchar(50)


	SELECT 	@EntityName = E.Name
	FROM Entity E 
	WHERE E.ID = @EntityID

	SELECT 	@GameName = G.Name
	FROM Game G 
	WHERE G.ID = @GameID

	SELECT 	@Login = U.UserName
	FROM Users U 
	WHERE U.UserID = @UserID


	INSERT INTO [GPSPoint]
	(
		[EntityName],
		[GameName],
		[Login],
		[Latitude],
		[Longitude],
		[Time],
		[Speed],
		[Altitude],
		[EntityID],
		[UserID],
		[GameID]
	)
	VALUES
	(
		@EntityName,
		@GameName,
		@Login,
		@Latitude,
		@Longitude,
		GetDate(),
		@Speed,
		@Altitude,
		@EntityID,
		@UserID,
		@GameID
	)

	RETURN @@Error
GO

 